unit Dm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, ADODB;

type
  TDmInt = class(TDataModule)
    Db: TDatabase;
    procedure Processkey(var Msg: Tmsg; var Handled: Boolean);
    procedure MyShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private declarations }

  end;

var
  DmInt: TDmInt;
  Nomeacesso: string;

implementation

{$R *.DFM}

procedure TDmInt.DataModuleCreate(Sender: TObject);
var
  list_params: TStrings;
begin

  if not Session.IsAlias('Industrial') then begin
    list_params := TStringList.Create;
    list_params.Add('SERVER NAME=acesso_industrial');
    list_params.Add('USER NAME=user_industrial');
    Session.AddAlias('Industrial', 'ORACLE', list_params);
    list_params.free;
    Session.SaveConfigFile;
  end;
  if not Session.IsAlias('Industrial1') then begin
    list_params := TStringList.Create;
    list_params.Add('SERVER NAME=acesso_industrial');
    list_params.Add('USER NAME=user_industrial1');
    Session.AddAlias('Industrial1', 'ORACLE', list_params);
    list_params.free;
    Session.SaveConfigFile;
  end;

  Application.OnMessage := ProcessKey;
  Application.OnShowHint := MyShowHint;
  try
    db.AliasName := 'Industrial';
    db.DatabaseName := 'Industrial';
    db.Connected := true;
  except
    db.AliasName := 'Industrial1';
    db.DatabaseName := 'Industrial1';
    db.Connected := true;
  end;
end;

procedure TDmInt.MyShowHint(var HintStr: string; var CanShow: Boolean;
  var HintInfo: THintInfo);
var
  i: integer;
begin
  for i := 0 to Application.ComponentCount - 1 do
    if Application.Components[i] is THintWindow then
      with THintWindow(Application.Components[i]).Canvas do begin
        Font.Name := 'Courier New';
        Font.Size := 08;
        Font.Style := [];
        HintInfo.HintColor := clInfoBk;
      end;
end;

procedure TDmInt.Processkey(var Msg: Tmsg; var Handled: Boolean);
begin
  if Msg.message = WM_KEYDOWN then begin
    if Msg.wParam = VK_RETURN then begin
      Msg.wParam := VK_CLEAR;
      Keybd_event(VK_TAB, 0, 0, 0);
    end;
  end;
end;

procedure TDmInt.DataModuleDestroy(Sender: TObject);
//var
//  list_params: TStrings;
begin
//  ESTA ROTINA ALTERAVA O ACESSO DO BANCO DE DADOS SEMPRE PARA "acesso_industrial".
//  if not FileExists('T:\LocalCriterius') then begin
//    with DmInt do begin
//      db.Connected := False;
//
//      Session.DeleteAlias('industrial');
//
//      list_params := TStringList.Create;
//      list_params.Add('SERVER NAME=acesso_industrial');
//      list_params.Add('USER NAME=user_industrial');
//      Session.AddAlias('Industrial', 'ORACLE', list_params);
//      list_params.free;
//      Session.SaveConfigFile;
//
//      Db.Connected := True;
//    end;
//  end;

end;

end.

